package concurrentp

import (
	"fmt"
	"runtime"
	"time"
)

func runA() {
	for i := 0; i < 7; i++ {
		fmt.Println("A:", i)
	}
}

func runB() {
	for i := 0; i < 7; i++ {
		fmt.Println("B:", i)
	}
}

func TestGoMaxProcs() {
	// 分配逻辑核数
	runtime.GOMAXPROCS(4)
	go runA()
	go runB()
	time.Sleep(time.Millisecond)
}

func TestRuntime() {
	go func(s string) {
		for i := 0; i < 2; i++ {
			fmt.Println(s)
		}
	}("Hello ")

	for i := 0; i < 2; i++ {
		// 切一下时间片，然后再重新分配
		runtime.Gosched()
		fmt.Println("World")
	}
}
